package com.ss.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ss.dao.ISysUserDao;
import com.ss.model.TSysuser;

@Repository("sysUserDao")
public class SysUserDaoImpl implements ISysUserDao {
	@Autowired
	protected SessionFactory sessionFactory;

	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public boolean isExist(TSysuser tsu) {
		Session session = this.getSession();
		String hql = "from TSysuser where userid =? and password = ?";
		Query query = session.createQuery(hql);
		query.setString(0, tsu.getUserid());
		query.setString(1, tsu.getPassword());
		if (query.list().size() >= 1) {
			return true;
		}
		return false;
	}

	@Override
	public List<TSysuser> getSysuserList(int page, int rows) {
		Session session = this.getSession();
		List<TSysuser> list = session.createQuery("from TSysuser")
				.setFirstResult((page - 1) * rows).setMaxResults(rows).list();
		return list;
	}

}
